package cetcbigdata.da.personal_service.beijing;

import cetcbigdata.da.base.DownloadAndUploadMinio;
import cn.wanghaomiao.xpath.model.JXDocument;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.jsoup.nodes.Element;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author YuanGongPing
 * @version 0.1
 * @description BeijingUtil
 * @since 2022/8/31 15:49
 */


public class BeijingUtil {
    public static JSONObject getBaseInfo(String html){
        try {
            // 基本信息
            JSONObject baseInfo = new JSONObject();
            JXDocument jxDocument = new JXDocument(html);
            List<Object> rs = jxDocument.sel("//*[@id='basic-main']//td[@class='td-name']");
            for (Object o : rs){
                String key  = ((Element) o).text();
                String value = ((Element) o).nextElementSibling().text();
                baseInfo.put(key, value);
            }

            Element titName  = (Element) jxDocument.selOne("//p[@class='tit-name']//span[@class='tit-span']");
            baseInfo.put("事项名称", titName.attr("title"));
            return baseInfo;
        }catch (Exception e){
            e.printStackTrace();
            return new JSONObject();
        }

    }

    public static JSONObject getHandlingProcedures(String html){
        try {
            // 办理流程
            JSONObject handlingProcedures = new JSONObject();
            // 办理流程信息
            JSONArray handlingProceduresInfo = new JSONArray();
            // 办理流程图
            JSONObject handlingProceduresImage = new JSONObject();
            String regex = "var process = ([\\s\\S]*?)};";
            Pattern pattern = Pattern.compile(regex);
            Matcher matcher = pattern.matcher(html);
            String data = null;
            while (matcher.find()) {
                data = matcher.group();
                data = data.replace("var process = ", "");
                data = data.replace(";", "");
                JSONArray itemProcessSubList = JSONObject.parseObject(data).getJSONArray("itemProcessSubList");
                for(Object o : itemProcessSubList){
                    JSONObject temp = (JSONObject) o;
                    JSONObject resItemProcessSub = new JSONObject();
                    resItemProcessSub.put("办理环节", temp.getString("PHASE_STD_NAME"));
                    resItemProcessSub.put("办理步骤",temp.getString("PHASE_NAME"));
                    resItemProcessSub.put("办理时限", getBlTime(temp.getString("PHASE_LIMIT_TYPE"), temp.getString("PHASE_LIMIT")));
                    if(temp.getString("PHASE_NAME").equals("送达")){
                        resItemProcessSub.put("送达方式：", getSendType(temp.getString("SENDTYPE"), temp ));
                    }else {
                        resItemProcessSub.put("办理人员", JSONObject.parseObject(temp.getString("DATAJSONTEXT")).getString("HANDLE_PERSON"));
                        resItemProcessSub.put("审查标准", temp.containsKey("PHASE_APPROVE") ? temp.getString("PHASE_APPROVE") : "");
                        resItemProcessSub.put("办理结果", temp.getString("PHASE_RESULT"));
                    }
                    handlingProceduresInfo.add(resItemProcessSub);
                }
            }

            // 解析流程图地址，并添加至resItemProcessSubList 列表中
            handlingProceduresImage.put("流程图名称", JSONObject.parseObject(data).getJSONObject("systemDocument").getString("DOC_NAME"));
            String fileUrl = String.format("http://banshi.beijing.gov.cn/pubtask/download/%s.%s",
                    JSONObject.parseObject(data).getJSONObject("systemDocument").getString("DOC_ID"),
                    JSONObject.parseObject(data).getJSONObject("systemDocument").getString("DOC_EXT")
            );
            handlingProceduresImage.put("流程图地址", fileDownloadAndUploadMinioGetImage(
                    fileUrl, JSONObject.parseObject(data).getJSONObject("systemDocument").getString("DOC_NAME"))
            );

            handlingProcedures.put("办理流程信息", handlingProceduresInfo);
            handlingProcedures.put("办理流程图", handlingProceduresImage);
            return handlingProcedures;
        }catch (Exception e){
            e.printStackTrace();
            return new JSONObject();
        }
    }

    public static JSONArray getMaterialAll(String html){
        try {
            JSONArray materialList = new JSONArray();
            JXDocument jxDocument = new JXDocument(html);
            String regex = "var material = ([\\s\\S]*?)];";
            Pattern pattern = Pattern.compile(regex);
            Matcher matcher = pattern.matcher(html);
            String data = null;
            while (matcher.find()) {
                data = matcher.group();
                data = data.replace("var material = ", "");
                data = data.replace(";", "");
                JSONArray itemProcessSubList = JSONObject.parseArray(data);
                for (Object o : itemProcessSubList) {
                    JSONObject temp = (JSONObject) o;
                    materialList.add(getMaterial(temp));

                }
            }
            JSONObject temp = new JSONObject();
            Element node = (Element) jxDocument.selOne("//*[@id='apply-table']/tbody");
            temp.put("申请材料总要求", node == null ? "" : node.text().replace("申请材料总要求", ""));
            materialList.add(temp);
            return materialList;
        }catch (Exception e){
            e.printStackTrace();
            return new JSONArray();
        }
    }

    public static JSONObject getMaterial(JSONObject data){
        JSONObject item = new JSONObject();
        item.put("简介", data.getString("G_SUMMARY"));
        if(data.getString("G_TYPE").equals("0")){
            item.put("名称", data.getString("M_INDEX") + "、"+ data.getString("G_NAME"));
        }else {
            item.put("序号", data.getString("M_INDEX") );
            String G_NAME = isNotBlankOrNull(data.getString("PREFIX_NAME")) ? data.getString("PREFIX_NAME"):
                    "" + data.getString("G_NAME") + (isNotBlankOrNull(data.getString("SUFFIX_NAME")) ? data.getString("SUFFIX_NAME"):"");
            item.put("材料名称", G_NAME );

            String M_SOURCE =  data.getString("M_SOURCE").equals("10") ? "申请人自备" :
                    data.getString("M_SOURCE").equals("20") ? "政府部门核发":
                            data.getString("M_SOURCE").equals("30") ? "中介机构或法定机构产生":
                                    data.getString("M_SOURCE").equals("99") ? "其他": "-";
            if(isNotBlankOrNull(data.getString("CERT_OFFICE"))){
                M_SOURCE += "来源说明：" + data.getString("CERT_OFFICE");
            }
            item.put("材料来源", M_SOURCE );

            String ISNEED = data.getString("ISNEED").equals("1") ?
                    "必要" : data.getString("ISNEED").equals("2") ?
                    "非必要" :  data.getString("ISNEED").equals("3") ? "容缺后补" : "无";
            item.put("材料必要性", ISNEED );


            String NUM = "";
            if(isNotBlankOrNull(data.getString("ORIGINAL_NUM"))
                    && isNotBlankOrNull(data.getString("DUPLICATE_NUM"))
                    && isNotBlankOrNull(data.getString("COPY_NUM"))
                    && isNotBlankOrNull(data.getString("DUPLICATE_COPY_NUM"))
                    && isNotBlankOrNull(data.getString("ORIGINAL_NUM"))
                    && isNotBlankOrNull(data.getString("IS_CHECK"))
                    && isNotBlankOrNull(data.getString("OTHER_NUM"))){
                NUM = "不涉及";

            }else  if(data.getString("M_TYPE").equals("03") || data.getString("M_TYPE").equals("05")){
                if(isNotBlankOrNull(data.getString("ORIGINAL_NUM"))){
                    NUM += (isNotBlankOrNull(data.getString("IS_RESERVED")) ? "正本":"") + "原件" +
                            (isNotBlankOrNull(data.getString("ORIGINAL_NUM"))?
                                    data.getString("ORIGINAL_NUM")+"份":"") +
                            (isNotBlankOrNull(data.getString("IS_CHECK")) ? isNotBlankOrNull(data.getString("IS_RESERVED")) ?"（正本原件仅供查验）":"（原件仅供查验)":"");

                    if(isNotBlankOrNull(data.getString("DUPLICATE_NUM")) ||
                            isNotBlankOrNull(data.getString("COPY_NUM")) ||
                            isNotBlankOrNull(data.getString("DUPLICATE_COPY_NUM")) ||
                            isNotBlankOrNull(data.getString("OTHER_NUM"))){
                        NUM+='；';
                    }
                }
                if(isNotBlankOrNull(data.getString("DUPLICATE_NUM"))){
                    NUM += (
                            isNotBlankOrNull(data.getString("IS_DUPLICATE"))?
                                    "副本":"")+"原件"+(
                            isNotBlankOrNull(data.getString("DUPLICATE_NUM")) ?
                                    data.getString("DUPLICATE_NUM")+"份":"")+(
                            isNotBlankOrNull(data.getString("IS_DUPLICATE_CHECK")) ?
                                    "（副本原件仅供查验）":"");
                    if(isNotBlankOrNull(data.getString("COPY_NUM"))  || isNotBlankOrNull(data.getString("DUPLICATE_COPY_NUM"))|| isNotBlankOrNull(data.getString("OTHER_NUM")) ){
                        NUM+='；';
                    }
                }
                if(isNotBlankOrNull(data.getString("COPY_NUM"))){
                    NUM += (isNotBlankOrNull(data.getString("IS_RESERVED")) ? "正本" : "") + "复印件"+ (isNotBlankOrNull(data.getString("COPY_NUM"))? data.getString("COPY_NUM") + "份" : "");
                    if(isNotBlankOrNull(data.getString("DUPLICATE_COPY_NUM")) || isNotBlankOrNull(data.getString("OTHER_NUM"))){
                        NUM+='；';
                    }
                }
                if(isNotBlankOrNull(data.getString("DUPLICATE_COPY_NUM"))){
                    NUM +=  (isNotBlankOrNull(data.getString("IS_DUPLICATE")) ? "副本":"")+"复印件"+(isNotBlankOrNull(data.getString("DUPLICATE_COPY_NUM"))?
                            data.getString("DUPLICATE_COPY_NUM") +"份":"");
                    if(isNotBlankOrNull(data.getString("OTHER_NUM"))){
                        NUM +='；';
                    }
                }
            } else {
                NUM = isNotBlankOrNull(data.getString("ORIGINAL_NUM")) ? "原件" + data.getString("ORIGINAL_NUM") + "份" : "" + (isNotBlankOrNull(data.getString("IS_CHECK")) ? "（原件仅供查验）":"");
                if(isNotBlankOrNull(data.getString("ORIGINAL_NUM")) && isNotBlankOrNull(data.getString("COPY_NUM"))){
                    NUM += '；';
                }
                NUM += isNotBlankOrNull(data.getString("COPY_NUM")) ? "复印件" + data.getString("COPY_NUM") + "份":"";
                if(isNotBlankOrNull(data.getString("COPY_NUM")) && isNotBlankOrNull(data.getString("OTHER_NUM"))) {
                    NUM += '；';
                }
            }
            NUM += (isNotBlankOrNull(data.getString("OTHER_NUM")) ? "原件" + data.getString("OTHER_NUM")+'份':"");
            item.put("数量要求", NUM );

            String M_TYPE = "";

            if(data.getInteger("M_TYPE") == 0 && data.getInteger("M_MEDIA") == 0){
                M_TYPE += "--";
            }
            else{
                M_TYPE += (data.getString("M_TYPE").equals("01") ? "表格类；":
                        data.getString("M_TYPE").equals("02")? "文本类；":
                                data.getString("M_TYPE").equals("03") ? "结果文书类；":
                                        data.getString("M_TYPE").equals("04") ? "其他；":
                                                data.getString("M_TYPE").equals("05") ?"结果文书类；":"")
                        +(data.getString("M_MEDIA").equals("1")? "纸质":
                        data.getString("M_MEDIA").equals("2")?"电子":data.getString("M_MEDIA").equals("3")?"纸质、电子":"");
            }
            item.put("介质要求", M_TYPE );


            JSONArray tableDownload = new JSONArray();
            if(isNotBlankOrNull(data.getJSONObject("systemDocumentATT1")) && data.getString("M_TYPE").equals("01")){
                JSONObject tableDownloadItem = new JSONObject();
                tableDownloadItem.put("样表", data.getJSONObject("systemDocumentATT1").getString("DOC_NAME"));
                tableDownloadItem.put("minioId", fileDownloadAndUploadMinioPost(
                        data.getJSONObject("systemDocumentATT1").getString("DOC_ID"),
                        data.getJSONObject("systemDocumentATT1").getString("DOC_EXT"),
                        data.getJSONObject("systemDocumentATT1").getString("DOC_NAME")
                ));
                tableDownload.add(tableDownloadItem);
            }
            if(isNotBlankOrNull(data.getJSONObject("systemDocumentATT2")) && data.getString("M_TYPE").equals("01")){
                JSONObject tableDownloadItem = new JSONObject();
                tableDownloadItem.put("空表", data.getJSONObject("systemDocumentATT2").getString("DOC_NAME"));
                tableDownloadItem.put("minioId", fileDownloadAndUploadMinioPost(
                        data.getJSONObject("systemDocumentATT2").getString("DOC_ID"),
                        data.getJSONObject("systemDocumentATT2").getString("DOC_EXT"),
                        data.getJSONObject("systemDocumentATT2").getString("DOC_NAME")
                ));
                tableDownload.add(tableDownloadItem);

            }

            if(isNotBlankOrNull(data.getJSONObject("systemDocumentATT3")) && data.getString("M_TYPE").equals("02")){
                JSONObject tableDownloadItem = new JSONObject();
                tableDownloadItem.put("范本：", data.getJSONObject("systemDocumentATT3").getString("DOC_NAME"));
                tableDownloadItem.put("minioId", fileDownloadAndUploadMinioPost(
                        data.getJSONObject("systemDocumentATT3").getString("DOC_ID"),
                        data.getJSONObject("systemDocumentATT3").getString("DOC_EXT"),
                        data.getJSONObject("systemDocumentATT3").getString("DOC_NAME")
                ));
                tableDownload.add(tableDownloadItem);
            }
            item.put("表格及样表下载", tableDownload );


            String other = "";
            other += "受理标准:" + (isNotBlankOrNull(data.getString("AUDIT_POINT")) ? data.getString("AUDIT_POINT") +";":"");

            other += "提供材料依据:" + (isNotBlankOrNull(data.getString("MATERIALSEVIDENCE")) ? data.getString("MATERIALSEVIDENCE") +";":"");

            other += "材料规格:" + (isNotBlankOrNull(data.getString("PAGEFORMAT")) ? data.getString("PAGEFORMAT") +";":"");

            other += "备注:" + (isNotBlankOrNull(data.getString("REMARK")) ? data.getString("REMARK") +";" :"");

            other += (isNotBlankOrNull(data.getString("REQUIREMENT")) ? data.getString("REQUIREMENT") +";" :"");

            item.put("其他要求", other );
        }
        return item;
    }

    public static JSONArray getResult(String html){
        try {
            JSONArray resultList = new JSONArray();
            String regex = "var result = ([\\s\\S]*?);";
            Pattern pattern = Pattern.compile(regex);
            Matcher matcher = pattern.matcher(html);
            String data = null;
            while (matcher.find()) {
                data = matcher.group();
                data = data.replace("var result = ", "");
                data = data.replace(";", "");
                JSONArray itemProcessSubList = JSONObject.parseArray(data);
                for(Object o : itemProcessSubList){
                    JSONObject result = new JSONObject();
                    JSONObject temp1 = (JSONObject) o;
                    result.put("结果名称", temp1.getString("RESULTNAME"));
                    result.put("结果名称-文件", fileDownloadAndUploadMinioGet(temp1.getString("DOC_ID") + temp1.getString("DOC_NAME").split("\\.")[1], temp1.getString("DOC_NAME")) );
                    result.put("结果文书类型",
                            (temp1.getString("RESULTTYPE").equals("01") ? "证照" :
                                    temp1.getString("RESULTTYPE").equals("02")  ? "批文" :
                                            temp1.getString("RESULTTYPE").equals("03") ? "合同" :
                                                    temp1.getString("RESULTTYPE").equals("04") ? "登记表" :
                                                            temp1.getString("RESULTTYPE").equals("05") ? "其他": "") + (
                                    temp1.getString("RESULTTYPE").equals("05") && isNotBlankOrNull(temp1.getString("RESULTTYPE_EXP")) ? temp1.getString("RESULTTYPE_EXP"):"")
                    );
                    result.put("结果样本", temp1.getString("DOC_NAME"));
                    result.put("有效时间", temp1.getInteger("RESULT_LIMIT") < 5 ? temp1.getString("RESULT_LIMIT")+"年" :
                            temp1.getInteger("RESULT_LIMIT") == 5 ? "无时限" :
                                    temp1.getString("RESULT_LIMIT").equals("9") ?
                                            isNotBlankOrNull(temp1.getString("EFFECTIVEDATE_EXP") ) ? temp1.getString("EFFECTIVEDATE_EXP") : "见结果文书":""
                    );
                    resultList.add(result);
                }
            }
            return resultList;
        }catch (Exception e){
            e.printStackTrace();
            return new JSONArray();
        }
    }

    public static JSONArray getApproval(String html){
        try {
            JSONArray approveList = new JSONArray();
            String regex = "var law = ([\\s\\S]*?)}];";
            Pattern pattern = Pattern.compile(regex);
            Matcher matcher = pattern.matcher(html);
            String data = null;
            while (matcher.find()) {
                data = matcher.group();
                data = data.replace("var law = ", "");
                data = data.replace(";", "");
                JSONArray itemProcessSubList = JSONObject.parseArray(data);
                for(Object o : itemProcessSubList){
                    JSONObject result = new JSONObject();
                    JSONObject temp1 = (JSONObject) o;
                    result.put("制定机关", temp1.getString("LAW_OWNER"));
                    result.put("依据名称", temp1.getString("LAW_NAME"));
                    result.put("依据名称-文件", temp1.getString("LAW_URL"));
                    result.put("发布号令（文号）", temp1.getString("LAW_CODE"));
                    result.put("法条（具体规定）内容", temp1.getString("LAW_CONTENT"));
                    approveList.add(result);
                }
            }
            return approveList;
        }catch ( Exception e){
            e.printStackTrace();
            return new JSONArray();
        }
    }

    public static JSONArray getStandardList(String html){
        try {
            JSONArray standardList = new JSONArray();
            String regex = "var feeproject = ([\\s\\S]*?)];";
            Pattern pattern = Pattern.compile(regex);
            Matcher matcher = pattern.matcher(html);
            String data = null;
            while (matcher.find()) {
                data = matcher.group();
                data = data.replace("var feeproject = ", "");
                data = data.replace(";", "");
                JSONArray itemProcessSubList = JSONObject.parseArray(data);
                for(Object o : itemProcessSubList){
                    JSONObject result = new JSONObject();
                    JSONObject temp1 = (JSONObject) o;
                    result.put("收费项目名称", temp1.getString("FEENAME"));
                    result.put("收费标准", temp1.getString("FEESTAND"));
                    result.put("收费依据", temp1.getString("BYLAW"));
                    try {
                        result.put("是否允许减免", temp1.getString("ISDESC").equals("1") ?
                                "减免收费情形：" + temp1.getString("FEEREDUCTIONSITUATION") + ";" +  "允许减免依据：" + temp1.getString("DESCEXPLAIN") + ";": "否");
                    }catch (Exception e){
                        result.put("是否允许减免", "否");
                    }
                    result.put("备注", temp1.getString("REMARK"));
                    standardList.add(result);
                }
            }
            return  standardList;
        }catch (Exception e){
            e.printStackTrace();
            return new JSONArray();
        }
    }

    public static List<String> getSendType(String types, JSONObject value){
        String [] typeArr = types.split("\\^");
        List<String> res = new ArrayList<>();
        for(String type : typeArr){
            String item = getSendTypeUnit(Integer.parseInt(type), value);
            res.add(item);
        }
        return res;
    }

    public static String getSendTypeUnit(int i, JSONObject value){
        String res = "";
        switch (i){
            case 0:
                res = "窗口领取";
                break;
            case 1:
                res = "公告送达";
                break;
            case 2:
                res = "邮寄送达";
                break;
            case 6:
                res = "直接送达";
                break;
            case 7:
                res = "留置送达";
                break;
            case 8:
                res = "自助柜";
                break;
            case 4:
                res = String.format("网站下载:%s", value.getString("SENDURL"));
                break;
            case 5:
                res = String.format("其他:%s", value.getString("SENDEXPLAIN"));
                break;
            default:
                res = "其他";
                break;
        }
        return res;
    }

    public static String getBlTime(String PHASE_LIMIT_TYPE, String PHASE_LIMIT) {
        String jmStr = "";
        if (PHASE_LIMIT_TYPE.equals("1")) {
            if (isNotBlankOrNull(PHASE_LIMIT) ) {
                jmStr = PHASE_LIMIT + "个工作日";
            }
        } else if (PHASE_LIMIT_TYPE.equals("2")) {
            if (isNotBlankOrNull(PHASE_LIMIT) ) {
                jmStr = PHASE_LIMIT + "个自然日";
            }
        } else if ( PHASE_LIMIT_TYPE.equals("3")) {
            if (isNotBlankOrNull(PHASE_LIMIT)) {
                jmStr = PHASE_LIMIT + "个月";
            }
        }else{
            jmStr = "";
        }
        return jmStr;
    }

    public static String fileDownloadAndUploadMinioPost(String docId, String docExt, String docName){
        JSONObject downloadParam = new JSONObject();
        JSONArray arr = new JSONArray();
        JSONObject param = new JSONObject();
        param.put("docId", docId);
        param.put("docExt", docExt);
        param.put("docName", docName);
        arr.add(param);
        String encodeStr =  Js.getEncode(arr.toJSONString());
        downloadParam.put("document", encodeStr);
        JSONObject headers = new JSONObject();
        headers.put("Host","banshi.beijing.gov.cn");
        headers.put("Origin","http://banshi.beijing.gov.cn");
        headers.put("Referer","http://banshi.beijing.gov.cn/pubtask/task/1/110000000000/24acbdb5-9565-11e9-8300-507b9d3e4710.html?locationCode=110000000000&serverType=1001");
        headers.put("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36");
        return DownloadAndUploadMinio.getInstance().downloadPost(
                "http://banshi.beijing.gov.cn/guideservice/document/yjFile",
                headers,
                downloadParam,
                docName
        );
    }

    public static String fileDownloadAndUploadMinioGet(String docId, String fileName) throws Exception {
        JSONObject param = new JSONObject();
        JSONObject headers = new JSONObject();
        headers.put("Host","banshi.beijing.gov.cn");
        headers.put("Origin","http://banshi.beijing.gov.cn");
        headers.put("Referer","http://banshi.beijing.gov.cn/pubtask/task/1/110000000000/24acbdb5-9565-11e9-8300-507b9d3e4710.html?locationCode=110000000000&serverType=1001");
        headers.put("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36");
        return DownloadAndUploadMinio.getInstance().downloadGet(
                "http://banshi.beijing.gov.cn/pubtask/download/" + docId,
                headers,
                param,
                fileName
        );
    }

    public static String fileDownloadAndUploadMinioGetImage(String url, String fileName ) throws Exception {
        JSONObject param = new JSONObject();
        JSONObject headers = new JSONObject();
        headers.put("Host","banshi.beijing.gov.cn");
        headers.put("Origin","http://banshi.beijing.gov.cn");
        headers.put("Referer","http://banshi.beijing.gov.cn/pubtask/task/1/110000000000/24acbdb5-9565-11e9-8300-507b9d3e4710.html?locationCode=110000000000&serverType=1001");
        headers.put("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36");
        return DownloadAndUploadMinio.getInstance().downloadGet(
                url,
                headers,
                param,
                fileName
        );
    }

    /*******
     *  判断是否为null 或者 空字符串
     * @param str
     * @return
     */
    public static boolean isNotBlankOrNull(Object str){
        return str != null && !str.toString().equals("");
    }


    public static List<JSONObject> getRegionList(){
        String response = "{\"success\":true,\"code\":\"200\",\"data\":{\"locationName\":\"北京市\",\"orderNum\":0,\"id\":\"110000000000\",\"classification\":\"2\",\"delFlag\":\"0\",\"parentId\":\"1\",\"childNode\":[{\"locationName\":\"东城区\",\"orderNum\":1,\"id\":\"110101000000\",\"classification\":\"3\",\"delFlag\":\"0\",\"parentId\":\"110000000000\"},{\"locationName\":\"西城区\",\"orderNum\":2,\"id\":\"110102000000\",\"classification\":\"3\",\"delFlag\":\"0\",\"parentId\":\"110000000000\"},{\"locationName\":\"朝阳区\",\"orderNum\":3,\"id\":\"110105000000\",\"classification\":\"3\",\"delFlag\":\"0\",\"parentId\":\"110000000000\"},{\"locationName\":\"丰台区\",\"orderNum\":4,\"id\":\"110106000000\",\"classification\":\"3\",\"delFlag\":\"0\",\"parentId\":\"110000000000\"},{\"locationName\":\"石景山区\",\"orderNum\":5,\"id\":\"110107000000\",\"classification\":\"3\",\"delFlag\":\"0\",\"parentId\":\"110000000000\"},{\"locationName\":\"海淀区\",\"orderNum\":6,\"id\":\"110108000000\",\"classification\":\"3\",\"delFlag\":\"0\",\"parentId\":\"110000000000\"},{\"locationName\":\"门头沟区\",\"orderNum\":7,\"id\":\"110109000000\",\"classification\":\"3\",\"delFlag\":\"0\",\"parentId\":\"110000000000\"},{\"locationName\":\"房山区\",\"orderNum\":8,\"id\":\"110111000000\",\"classification\":\"3\",\"delFlag\":\"0\",\"parentId\":\"110000000000\"},{\"locationName\":\"副中心（通州区）\",\"orderNum\":9,\"id\":\"110112000000\",\"classification\":\"3\",\"delFlag\":\"0\",\"parentId\":\"110000000000\"},{\"locationName\":\"顺义区\",\"orderNum\":10,\"id\":\"110113000000\",\"classification\":\"3\",\"delFlag\":\"0\",\"parentId\":\"110000000000\"},{\"locationName\":\"昌平区\",\"orderNum\":11,\"id\":\"110114000000\",\"classification\":\"3\",\"delFlag\":\"0\",\"parentId\":\"110000000000\"},{\"locationName\":\"大兴区\",\"orderNum\":12,\"id\":\"110115000000\",\"classification\":\"3\",\"delFlag\":\"0\",\"parentId\":\"110000000000\"},{\"locationName\":\"怀柔区\",\"orderNum\":13,\"id\":\"110116000000\",\"classification\":\"3\",\"delFlag\":\"0\",\"parentId\":\"110000000000\"},{\"locationName\":\"平谷区\",\"orderNum\":14,\"id\":\"110117000000\",\"classification\":\"3\",\"delFlag\":\"0\",\"parentId\":\"110000000000\"},{\"locationName\":\"密云区\",\"orderNum\":15,\"id\":\"110118000000\",\"classification\":\"3\",\"delFlag\":\"0\",\"parentId\":\"110000000000\"},{\"locationName\":\"延庆区\",\"orderNum\":16,\"id\":\"110119000000\",\"classification\":\"3\",\"delFlag\":\"0\",\"parentId\":\"110000000000\"},{\"locationName\":\"经济开发区\",\"orderNum\":17,\"id\":\"110115403000\",\"classification\":\"3\",\"delFlag\":\"0\",\"parentId\":\"110000000000\"}]}}";
        JSONArray data = JSONObject.parseObject(response).getJSONObject("data").getJSONArray("childNode");
        List<JSONObject> out = new ArrayList<>();
        for(Object o : data){
            out.add((JSONObject) o);
        }
        return out;
    }

    public static List<JSONObject> getTopic(){
        String response = "005,生育收养"+"\n"+
        "010,户籍办理"+"\n"+
        "015,民族宗教"+"\n"+
        "020,教育科研"+"\n"+
        "025,入伍服役"+"\n"+
        "030,就业创业"+"\n"+
        "035,设立变更"+"\n"+
        "040,准营准办"+"\n"+
        "045,抵押质押"+"\n"+
        "050,职业资格"+"\n"+
        "055,行政缴费"+"\n"+
        "060,婚姻登记"+"\n"+
        "065,优待抚恤"+"\n"+
        "070,规划建设"+"\n"+
        "075,住房保障"+"\n"+
        "085,社会保障（社会保险、社会救助）"+"\n"+
        "090,证件办理"+"\n"+
        "095,交通出行"+"\n"+
        "100,旅游观光"+"\n"+
        "105,出境入境"+"\n"+
        "110,消费维权"+"\n"+
        "115,公共安全"+"\n"+
        "120,司法公证"+"\n"+
        "125,知识产权"+"\n"+
        "130,环保绿化"+"\n"+
        "135,文化体育"+"\n"+
        "140,公用事业"+"\n"+
        "145,医疗卫生"+"\n"+
        "150,离职退休"+"\n"+
        "155,死亡殡葬"+"\n"+
        "998,地方特色分类"+"\n"+
        "999,其他";
        List<JSONObject> out = new ArrayList<>();
        for(String line : response.split("\n")){
            JSONObject item = new JSONObject();
            String [] temp = line.split(",");
            item.put("id", temp[0]);
            item.put("name",  temp[1]);
            out.add(item);
        }
        return out;
    }

    public static void main(String[] args) {

    }
}
